<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 事件日志数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\TimelogService;
use think\Exception;
use think\Request;

class TimelogController extends VerifyController
{
    protected $timelogService;

    public function __construct()
    {
        parent::__construct();
        $this->timelogService = TimelogService::getInstance();
    }

    /**
     * 添加时间日志计时器
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function addTimer(Request $request)
    {
        $param = $request->param();
        $resData = $this->timelogService->addTimer($param['data'], $request->getUserId());
        return json(success_response('', $resData));
    }


    /**
     * 停止时间日志计数器
     * @param Request $request
     * @return \think\Response
     */
    public function stopTimer(Request $request)
    {
        $param = $request->param();
        $resData = $this->timelogService->stopTimer($param['data']);
        return json(success_response('', $resData));
    }

    /**
     * 停止激活的时间日志
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function stopTimerByFilter(Request $request)
    {
        $param = $request->param();
        $resData = $this->timelogService->stopTimerByFilter($param['param']['filter'], $param['param']['module_code'], $request->getUserId());
        return json(success_response('', $resData));
    }

    /**
     * timelog修正
     * @param Request $request
     * @return \think\Response
     */
    public function timeLogCorrect(Request $request)
    {
        $param = $request->param()["param"];
        $resData = $this->timelogService->timeLogCorrect($param["filter"], $param["data"]);
        return json(success_response('', $resData));
    }

    /**
     * 获取个人最后执行过的时间日志
     * @param Request $request
     * @return \think\Response
     * @throws Exception
     */
    public function getLatestExecuteTimer(Request $request)
    {
        $resData = $this->timelogService->getLatestExecuteTimer($request->param()['param']['module_code'], $request->getUserId(), $request->getTenantId());
        return json(success_response('', $resData));
    }
}
